package com.example.androidtool

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.widget.LinearLayout
import android.widget.Toast
import androidx.annotation.Nullable
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.androidtool.databinding.ActivityMainBinding
import com.example.androidtool.databinding.DialogBottomSheetsBinding
import com.example.androidtool.edittext.EditTextActivity
import com.example.androidtool.notification.NotificationUtils
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.snackbar.Snackbar


/**
 * 这个页面只展示列表
 *
 * 然后创建一个功能package   一个package是一个功能
 *
 * */
class MainActivity : AppCompatActivity() {

    var mainAdp = MainAdp()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        var activityBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(activityBinding.root)
        activityBinding.recyclerView.layoutManager = LinearLayoutManager(this)
        activityBinding.recyclerView.adapter = mainAdp
        mainAdp.addData("相机")
        mainAdp.addData("普通Notification")
        mainAdp.addData("折叠式Notification")
        mainAdp.addData("悬挂式Notification")
        mainAdp.addData("底部动作条（Bottom Sheets）")
        mainAdp.addData("底部弹出提示（Snackbar）")
        mainAdp.addData("输入框的使用（EditText）")
        mainAdp.setOnItemClickListener { _, view, position ->
            when (position) {
                0 -> {

                }
                1 -> {
                    NotificationUtils.ordinaryNotification(this)
                }
                2 -> {
                    NotificationUtils.collapseNotification(this)
                }
                3 -> {
                    if (NotificationUtils.checkFloatPermission(this)) {
                        NotificationUtils.hangingNotice(this@MainActivity)
                    } else {
                        NotificationUtils.requestSettingCanDrawOverlays(this)
                    }
                }
                4 -> {
                    val inflate = DialogBottomSheetsBinding.inflate(layoutInflater)
                    var bottomSheetDialog = BottomSheetDialog(this)
                    bottomSheetDialog.setContentView(inflate.root)
                    bottomSheetDialog.show()
                }
                5 -> {
                    Snackbar.make(view, "标题", Snackbar.LENGTH_LONG).setAction("点击事件") {
                        Toast.makeText(view.context, "点击了", Toast.LENGTH_SHORT).show()
                    }.show()
                }
                6 -> {
                    startActivity(Intent(this, EditTextActivity::class.java))
                }
                else -> {
                    Toast.makeText(this@MainActivity, "暂未开放", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == NotificationUtils.MY_PERMISSION_REQUEST_CODE) {
            if (!NotificationUtils.checkFloatPermission(this@MainActivity)) {
                NotificationUtils.showPermissionDialog(this@MainActivity)
            } else {
                NotificationUtils.hangingNotice(this@MainActivity)
            }
        }
    }

}